home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / setprn.arc / SETPRN.ASM next >
Encoding:
Assembly Source File  |  1985-03-15  |  4.4 KB  |  102 lines

  1.  
  2.   COMMENT^ ** SETPRN.COM ** Last Rev. 12/11/83 ** Vincent T. Bly **
  3.  -------------------------------------------------------------------
  4. |                                                                   |
  5. | PURPOSE:  Provide a easy method of setting printer parameters     |
  6. |           from the DOS command level or from a batch file.        |
  7. |                                                                   |
  8. | FUNCTION: Send a user specified text string to the printer.       |
  9. |           The string may contain control characters consisting    |
  10. |           of decimal numbers enclosed in brackets ("[" and "]").  |
  11. |        The normal ending carriage return/line feed may be        |
  12. |        suppressed by a trailing semicolon (";") or comma (",") |
  13. |         in the same manner as the BASIC LPRINT command.        |
  14. |                                    |
  15. | TO USE:   From DOS, type SETPRN followed by a space and the text  |
  16. |           string, then press <enter>.  For examples, see the file |
  17. |        SETPRN.DOC                            |
  18. |                                                                   |
  19.  -------------------------------------------------------------------^
  20.  
  21. CSEG        SEGMENT
  22.         ASSUME    CS:CSEG,DS:CSEG
  23.  
  24.         ORG    80H ;----------- in Program Segment Prefix
  25. NUM_CHARS    LABEL    BYTE        ;number of characters in argument
  26.         ORG    82H
  27. ARGTX        LABEL    BYTE        ;start of text (after leading blank)
  28.  
  29.         ORG    100H ;---------- start of actual program
  30.  
  31. ;~~ Check argument & set-up to read it ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. START:        MOV    BX,OFFSET ARGTX    ;point to start of text argument
  33.         MOV    CL,[NUM_CHARS]    ;set CX to number of chars in argument
  34.         MOV    CH,0        ;    "
  35.         CMP    CX,2        ;is there at least 1 char after blank?
  36.         JB    CR_LF1        ;if not, print CR/LF & exit
  37.         SUB    CX,2        ;discount char count for leading blank
  38.                     ;and possible trailing "," or ";"
  39.         CMP    CX,0        ;is there only one character?
  40.         JE    TERM        ;if so, handle w/termination routine
  41.  
  42. ;~~~ Parse argument & convert control codes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. CHAR_2_PRN:    MOV    DL,[BX]        ;get character
  44.         CMP    DL,'['        ;is it the control prefix char?
  45.         JNE    SEND_IT        ;if not, go print char
  46.         MOV    AL,0        ;initialize char value to 0
  47.         MOV    DH,10D        ;digit multiplier
  48. CONVERT_DIGIT:    INC    BX        ;skip to next char
  49.         DEC    CX        ;    "
  50.         MOV    DL,[BX]        ;get char code into DL
  51.         JZ    EXIT2        ;exit if at end of text (CX = 0)
  52.         CMP    DL,']'        ;is it the control code suffix?
  53.         JE    PRE_SEND_IT    ;if so, go prepare to print code
  54.         SUB    DL,'0'        ;convert digit code to value
  55.         MUL    DH        ;mult. char value (in AL) by 10
  56.         ADD    AL,DL        ;add digit value to char value
  57.         JMP    CONVERT_DIGIT    ;loop back to convert next digit
  58. PRE_SEND_IT:    MOV    DL,AL        ;put converted code into DL
  59.  
  60. ;~~~ Send character to printer & loop back for next ~~~~~~~~~~~~~~~~~~~~~~~~~
  61. SEND_IT:    CALL    PRNT_CHR    ;go print character in DL
  62.         INC    BX        ;point to next character
  63.         LOOP    CHAR_2_PRN    ;repeat until done
  64.         
  65. ;~~~ Handle termination with ";" or "," ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. TERM:        MOV    DL,[BX]        ;get last character
  67.         CMP    DL,';'        ;is it a semicolon?
  68.         JE    COMPLETE    ;if so, skip to completion routine
  69.         CMP    DL,','        ;is it a comma?
  70.         JNE    CR_LF        ;if not, go print CR & LF
  71.         MOV    DL,09        ;set DL to tab character
  72.         CALL    PRNT_CHR    ;go print tab
  73.         JMP    COMPLETE    ;skip to completion routine
  74. CR_LF:        CALL    PRNT_CHR    ;go print last character
  75. CR_LF1:        MOV    DL,0DH        ;set DL to carriage return
  76.         CALL    PRNT_CHR    ;go print CR
  77.         MOV    DL,0AH        ;set DL to line feed
  78.         CALL     PRNT_CHR    ;go print LF
  79.  
  80. ;~~~ Display termination message & return to DOS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. COMPLETE:    MOV    DX,OFFSET MESSAGE ;point to completion message
  82.         MOV    AH,9        ;code for DOS display string function
  83.         INT    21H        ;display message via DOS function call
  84. EXIT1:        INT    20H        ;terminate via DOS function call
  85. MESSAGE:    DB    '* Done *$'
  86.  
  87. ;~~~ Send one character to printer via DOS function call ~~~~~~~~~~~~~~~~~~~~~
  88. PRNT_CHR:    MOV    AH,5        ;code for DOS printer output function
  89.         INT    21H        ;send to printer via DOS function call
  90.         RET            ;back to calling routine
  91.  
  92. ;~~~ Handle case where end of text encountered while parsing control code ~~~~
  93. EXIT2:        CMP    DL,']'        ;is it the control code suffix?
  94.         JNE    TERM        ;if not, go do normal completion
  95.                     ;(w/o printing control code)
  96.         MOV    DL,AL        ;put control code in DL
  97.         CALL    PRNT_CHR    ;go print control code
  98.         JMP    CR_LF        ;go print CR & LF & complete
  99.         
  100. CSEG        ENDS
  101.         
  102.         END    START